import {GUID} from '../guid';

export class TagProtocol {
  /**
   * 连接符
   *
   * @type {string}
   * @memberof TagProtocol
   */
  public connector: string = '%s_';
  /**
   * 测点格式
   *
   * @private
   * @type {string}@memberof TagProtocol
   */
  public format: string = this.connector + this.connector + this.connector + this.connector + this.connector;
  /**
   * 测点协议类型
   * 默认tagArrary
   * @private
   * @type {TagType}@memberof TagProtocol
   */
  public tagType: TagType = TagType.tagArrary;
  /**
   * 开始时间
   *
   * @type {Date}@memberof TagProtocol
   */
  public startTime?: Date;
  /**
   * 结束时间
   *
   * @type {Date}@memberof TagProtocol
   */
  public endTime?: Date;
  /**
   * 历史数据时间间隔（单位秒）
   *
   * @type {number}
   * @memberof TagProtocol
   */
  public historyInterval?: number;
  /**
   * 数据推送时间间隔（单位秒）
   *
   * @type {number}
   * @memberof TagProtocol
   */
  public pushInterval?: number;
  /**
   * 存放拼接完好测点的数组
   *
   * @private
   * @type {string[]}@memberof TagProtocol
   */
  public tagArrary: string[] = [];
  /**
   * 测点树形结构
   *
   * @private
   * @type {TagNode[]}@memberof TagProtocol
   */
  public tagTree: TagNode = {
    node: 'root',
    childs: [],
    tags: [],
    nodeId: GUID.getNewGUIDString()
  };

  constructor() {
    Object.defineProperty(this, 'connector', {enumerable: false});
  }

  /**
   * 根据this.tagType设置字段是否可枚举
   * 用于向服务发送数据时只发送协定好的数据
   *
   * @private
   *
   * @memberof TagProtocol
   */
  public setDefineProperty() {
    switch (this.tagType) {
      case TagType.tagArrary:
        Object.defineProperty(this, 'tagTree', {enumerable: false});
        Object.defineProperty(this, 'format', {enumerable: false});
        Object.defineProperty(this, 'tagArrary', {enumerable: true});
        break;
      case TagType.tagTree:
        Object.defineProperty(this, 'tagArrary', {enumerable: false});
        Object.defineProperty(this, 'tagTree', {enumerable: true});
        Object.defineProperty(this, 'format', {enumerable: true});
        break;
    }
  }


}

/**
 * 测点类型
 *
 * @export
 * @enum {number}
 */
export enum TagType {
  tagArrary = 1,
  tagTree = 2
}


/**
 * 测点节点
 *
 * @export
 * @interface TagNode
 */
export interface TagNode {
  node: string,
  childs?: TagNode[],
  tags?: string[],
  included?: boolean,
  nodeId?: string,
  levelId?: number,
}


// WEBPACK FOOTER //
// ./src/app/service/data-source/tag-protocol.ts
